package com.cmc.cloud.cmclink.doc.rpcservice.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.cmc.cloud.cmclink.doc.constants.errorconstant.ApiErrorCodeConstants;
import com.cmc.cloud.cmclink.doc.rpcservice.DictDataService;
import com.cmc.cloud.cmclink.system.api.api.dict.DictDataApi;
import com.cmc.cloud.cmclink.system.api.api.dict.dto.DictDataRespDTO;
import com.cmes.framework.common.exception.util.ServiceExceptionUtil;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.util.collection.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @author 周贤
 * @date 2025/11/3
 */
@Service
@Validated
@Slf4j
public class DictDataServiceImpl implements DictDataService {

    @Resource
    private DictDataApi  dictDataApi;


    @Override
    public List<String> getDictKeysList(String dictType) {
        List<DictDataRespDTO>  checkedData = null;
        try {
            CommonResult<List<DictDataRespDTO>> dictDataList = dictDataApi.getDictDataList(dictType);
            checkedData = dictDataList.getCheckedData();
        } catch (Exception e) {
            throw ServiceExceptionUtil.exception(ApiErrorCodeConstants.GET_DICT_DATA_ERROR);
        }
        if(CollectionUtil.isEmpty(checkedData)){
            Collections.emptyList();
        }
        return CollectionUtils.convertList(checkedData, DictDataRespDTO::getValue);
    }
}
